<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
 
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
sql: <input type="text" name="sql">
<input type="submit" value="提交">
</form>
<?php
echo $_POST["sql"]."</br>";
?>
<?php
//header('Content-type: text/html;charset=utf-8');
//PHP查询MySql数据库，将结果用表格输出
    
        $conn=mysql_connect("localhost","root","root");
        if(!$conn){
            echo "连接失败";
        }
        mysql_select_db("test",$conn);
        mysql_query("set names utf8");


        $sql=$_POST["sql"];A


        $res=mysql_query($sql,$conn);
        $rows=mysql_affected_rows($conn);//获取行数
        $colums=mysql_num_fields($res);//获取列数
        //echo "test数据库的"."$table_name"."表的所有用户数据如下：<br/>";
        echo "共计".$rows."行 ".$colums."列<br/>";
        
        echo '<table  border="1"><tr>';
        //for($i=0; $i < 100; $i++){
        for($i=0; ($i < $colums) and ( $i < 100); $i++){
            $field_name=mysql_field_name($res,$i);
            echo "<th>$field_name</th>";
        }
        echo "</tr>";
        while($row=mysql_fetch_row($res)){
            echo "<tr>";
            for($i=0; $i<$colums; $i++){
                echo "<td>$row[$i]</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
    
?>
</body>
</html>